<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/3
 * Time: 11:59
 */

namespace app\index\controller;

use tool\Common;

class Index
{
    public $app = [];
    public $token = '';
    public $path = '';

    public function index()
    {
        $url = "http://localhost/equipment/public/android/".$this->path;
        $post_data = [
            'token' => $this->token,
            'timestamp' => '2017-06-15 22:22:22',
            'app' => $this->app
        ];
        $checksum = $post_data['token'].$post_data['timestamp'].json_encode($post_data['app'],JSON_UNESCAPED_SLASHES |JSON_UNESCAPED_UNICODE);
        $post_data['checksum'] = md5($checksum);
        //echo json_encode($post_data);exit;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // post数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
        $output = curl_exec($ch);
        curl_close($ch);
        //打印获得的数据
        print_r($output);
    }

    public function login()
    {
        $this->app = [
            'password' => '123456',
            'account' => '13738190753',
        ];
        $this->path = 'user/login';
        $this->token = '';
        $this->index();
    }
    public function replacePassword()
    {
        $this->app = [
             "password"=>"123456",
             "rePassword"=>"123456"
        ];
        $this->path = 'User/replacePassword';
        $this->token = 'eccef4c5bc5af1a29bba7cf57a11d406';
        $this->index();
    }

    public function replyTopic()
    {
        $this->app = [
            "topicID" =>1,
            "contentID" => 0,
            "sendUserID" => 0,
            "content"=>"小编说的有道理"
        ];
        $this->path = 'topic/replyTopic';
        $this->token = 'bc582454060574b0f490b8c309b8f8a2';
        $this->index();
    }

    public function getReply()
    {
        $this->app = [
            "fireID" =>1,
            "contentID" =>1
        ];
        $this->path = 'fire/getReply';
        $this->token = 'bc582454060574b0f490b8c309b8f8a2';
        $this->index();
    }
    public function collectArticle()
    {
        $this->app = [
            "articleID" =>21
        ];
        $this->path = 'article/collectArticle';
        $this->token = '30fac5944e12f29b3920a0fe0dd29286';
        $this->index();
    }

    public function cancelCollect()
    {
        $this->app = [
            "articleID" =>21
        ];
        $this->path = 'article/cancelCollect';
        $this->token = '30fac5944e12f29b3920a0fe0dd29286';
        $this->index();
    }

    public function publishTopic()
    {
        $this->app = [
            "title"=> "测试数据",
            "content"=> "测试数据，图片显示",
            "imageURL"=> [
                [
                    "img"=> "http://master.patrol.qianchengwl.cn/Uploads/image/20170516/f7e9aeb23275064a4f53c4054c993699.jpg"
                ],
                [
                    "img"=> "http://master.patrol.qianchengwl.cn/Uploads/image/20170516/b714f916f9d95a7687e89d70e5049e7d.jpg"
                ]
            ]
        ];
        $this->path = 'topic/publishTopic';
        $this->token = '30fac5944e12f29b3920a0fe0dd29286';
        $this->index();
    }

    public function relatedForMe()
    {
        $this->app = [
            //"topicID" => 5
            'page' => 1,
            'count' => 2
        ];
        $this->path = 'fire/relatedForMe';
        $this->token = '6d85a6fb77b47f796da505b0edb9342f';
        $this->index();
    }
}
